package javaapplication1.control;

import javaapplication1.model.Pet;
import javaapplication1.service.PetOwnerService;
import javaapplication1.service.PetStoreService;
import javaapplication1.service.serviceImpl.PetOwnerServiceImpl;
import javaapplication1.service.serviceImpl.PetStoreServiceImpl;
import javaapplication1.view.MenuView;
import javaapplication1.view.SessionScope;

public class BuyPetControl {

	private PetOwnerService perOwnerService = new PetOwnerServiceImpl();
	private PetStoreService perStoreService = new PetStoreServiceImpl();

	public void buyPetControl(Pet pet) {
		if (SessionScope.getRole() == 1) {
			if (SessionScope.getMoney() < pet.getPrice()) {
				System.out.println("购买失败，用户金额不足");
			} else {
				perOwnerService.buy(pet);
				MenuView.menu();
			}
		} else if (SessionScope.getRole() == 2) {
			if (SessionScope.getBalance() < pet.getPrice()) {
				System.out.println("购买失败，商店结余不足");
			} else {
				perStoreService.buy(pet);
				MenuView.menu();
			}
		}
	}

}